
IF EXISTS(SELECT * FROM sys.columns
WHERE name='Remark' AND object_id=OBJECT_ID('BillInfo') AND max_length<1000)
BEGIN
	ALTER TABLE [dbo].BillInfo
	ALTER COLUMN Remark NVARCHAR(500) NULL
END
GO
IF EXISTS(SELECT * FROM sys.columns
WHERE name='Address' AND object_id=OBJECT_ID('Base_Organize') AND max_length<1000)
BEGIN
	ALTER TABLE dbo.Base_Organize
	ALTER COLUMN Address NVARCHAR(500) NULL
END
GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Base_DataItemDetail]') AND name = N'index_dataitemdetail')
DROP INDEX [index_dataitemdetail] ON [dbo].[Base_DataItemDetail]
GO

IF EXISTS(SELECT * FROM sys.columns
WHERE name='ItemName' AND object_id=OBJECT_ID('Base_DataItemDetail') AND max_length<800)
BEGIN
	ALTER TABLE [dbo].Base_DataItemDetail
	ALTER COLUMN ItemCode NVARCHAR(400) NULL

	ALTER TABLE [dbo].Base_DataItemDetail
	ALTER COLUMN ItemName NVARCHAR(400) NULL

	ALTER TABLE [dbo].Base_DataItemDetail
	ALTER COLUMN ItemValue NVARCHAR(400) NULL
END
GO



IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Base_DataItemDetail]') AND name = N'index_dataitemdetail')
CREATE NONCLUSTERED INDEX [index_dataitemdetail] ON [dbo].[Base_DataItemDetail]
(
	[ItemId] ASC,
	[ItemName] ASC,
	[ItemValue] ASC
)
GO

IF EXISTS(SELECT * FROM sys.columns
WHERE name='BillNo' AND object_id=OBJECT_ID('BillFeeDetail') AND max_length<200)
BEGIN
	ALTER TABLE [dbo].BillFeeDetail
	ALTER COLUMN BillNo NVARCHAR(100) NULL
END
GO

IF EXISTS(SELECT * FROM sys.columns
WHERE name='RealName' AND object_id=OBJECT_ID('Base_User') AND max_length<800)
BEGIN
	ALTER TABLE [dbo].Base_User
	ALTER COLUMN RealName NVARCHAR(400) NULL
END
GO

IF EXISTS(SELECT * FROM sys.columns
WHERE name='Address' AND object_id=OBJECT_ID('Clinic') AND max_length<800)
BEGIN
	ALTER TABLE [dbo].[Clinic]
	ALTER COLUMN [Address] NVARCHAR(400) NULL

	ALTER TABLE [dbo].Clinic
	ALTER COLUMN NAME NVARCHAR(400) NULL

	ALTER TABLE [dbo].Clinic
	ALTER COLUMN TEL NVARCHAR(400) NULL

	ALTER TABLE [dbo].Clinic
	ALTER COLUMN FAX NVARCHAR(400) NULL
END
GO

IF EXISTS(SELECT * FROM sys.columns
WHERE name='TITLE' AND object_id=OBJECT_ID('DoctorMain') AND max_length<800)
BEGIN
	ALTER TABLE [dbo].DoctorMain
	ALTER COLUMN TITLE NVARCHAR(400) NULL
END
GO

IF EXISTS(SELECT * FROM sys.columns
WHERE name='EnCode' AND object_id=OBJECT_ID('Material') AND max_length<800)
BEGIN
	ALTER TABLE [dbo].Material
	ALTER COLUMN EnCode NVARCHAR(400) NULL
	
	ALTER TABLE [dbo].Material
	ALTER COLUMN UnitName NVARCHAR(400) NULL

	ALTER TABLE [dbo].Material
	ALTER COLUMN Remark NVARCHAR(MAX) NULL

	ALTER TABLE [dbo].Material
	ALTER COLUMN TakingRemark NVARCHAR(500) NULL

	ALTER TABLE [dbo].Material
	ALTER COLUMN ChromaUnitName NVARCHAR(400) NULL

	ALTER TABLE [Material]
	ALTER COLUMN [Name] NVARCHAR(200) NULL

END
GO

IF EXISTS(SELECT * FROM sys.columns
WHERE name='ItemName' AND object_id=OBJECT_ID('MedicalHistory') AND max_length<800)
BEGIN
	ALTER TABLE [dbo].MedicalHistory
	ALTER COLUMN ItemName NVARCHAR(400) NULL
END
GO

IF EXISTS(SELECT * FROM sys.columns
WHERE name='HKId' AND object_id=OBJECT_ID('PatientMain') AND max_length<800)
BEGIN
	ALTER TABLE [dbo].PatientMain
	ALTER COLUMN HKId NVARCHAR(400) NULL

	ALTER TABLE [dbo].PatientMain
	ALTER COLUMN EnglishName NVARCHAR(400) NULL

	ALTER TABLE [dbo].PatientMain
	ALTER COLUMN Name NVARCHAR(400) NULL

	ALTER TABLE [dbo].PatientMain
	ALTER COLUMN Prefix NVARCHAR(400) NULL

	ALTER TABLE [dbo].PatientMain
	ALTER COLUMN Mobile NVARCHAR(400) NULL

	ALTER TABLE [dbo].PatientMain
	ALTER COLUMN Phone NVARCHAR(400) NULL

	ALTER TABLE [dbo].PatientMain
	ALTER COLUMN Occupation NVARCHAR(400) NULL

	ALTER TABLE [dbo].PatientMain
	ALTER COLUMN Introducer NVARCHAR(400) NULL

	ALTER TABLE [dbo].PatientMain
	ALTER COLUMN DIC NVARCHAR(400) NULL

	ALTER TABLE [dbo].PatientMain
	ALTER COLUMN insurer NVARCHAR(400) NULL

	ALTER TABLE [dbo].PatientMain
	ALTER COLUMN Email NVARCHAR(400) NULL

	ALTER TABLE [dbo].PatientMain
	ALTER COLUMN MOME NVARCHAR(MAX) NULL

	ALTER TABLE [dbo].PatientMain
	ALTER COLUMN DetailedAddress NVARCHAR(MAX) NULL

	ALTER TABLE [dbo].PatientMain
	ALTER COLUMN BusDetailedAddress NVARCHAR(MAX) NULL

	ALTER TABLE [dbo].PatientMain
	ALTER COLUMN REMARKS NVARCHAR(MAX) NULL
END
GO

IF EXISTS(SELECT * FROM sys.columns
WHERE name='PaymentMethod' AND object_id=OBJECT_ID('PaymentMethodManage') AND max_length<800)
BEGIN
	ALTER TABLE [dbo].PaymentMethodManage
	ALTER COLUMN PaymentMethod NVARCHAR(400) NULL
END
GO

IF EXISTS(SELECT * FROM sys.columns
WHERE name='FullName' AND object_id=OBJECT_ID('Supplier') AND max_length<800)
BEGIN
	ALTER TABLE [dbo].Supplier
	ALTER COLUMN FullName NVARCHAR(400) NULL

	ALTER TABLE [dbo].Supplier
	ALTER COLUMN EnCode NVARCHAR(400) NULL

	ALTER TABLE [dbo].Supplier
	ALTER COLUMN DetailedAddress NVARCHAR(500) NULL

	ALTER TABLE [dbo].Supplier
	ALTER COLUMN Mobile NVARCHAR(500) NULL

	ALTER TABLE [dbo].Supplier
	ALTER COLUMN Phone NVARCHAR(500) NULL

	ALTER TABLE [dbo].Supplier
	ALTER COLUMN Email NVARCHAR(500) NULL

	ALTER TABLE [dbo].Supplier
	ALTER COLUMN Header NVARCHAR(500) NULL
END
GO

IF EXISTS(SELECT * FROM sys.columns
WHERE name='Remark' AND object_id=OBJECT_ID('InterrogationReports') AND max_length<800)
BEGIN
	ALTER TABLE dbo.InterrogationReports
	ALTER COLUMN Remark NVARCHAR(4000) NULL
END
GO

IF EXISTS(SELECT * FROM sys.columns
WHERE name='EnCode' AND object_id=OBJECT_ID('AppointmentMain') AND max_length<800)
BEGIN
	ALTER TABLE dbo.AppointmentMain
	ALTER COLUMN EnCode NVARCHAR(400) NULL
END
GO

--IF EXISTS(SELECT * FROM sys.columns
--WHERE name='TimesPerDay' AND object_id=OBJECT_ID('ActionPrescriptionRecord') AND system_type_id=56)
--BEGIN	    
--	ALTER TABLE ActionPrescriptionRecord
--	ALTER COLUMN TimesPerDay DECIMAL(18,2)
--END
--GO


IF EXISTS(SELECT * FROM sys.columns
WHERE name='EnCode' AND object_id=OBJECT_ID('TestItems') AND max_length<1000)
BEGIN
	ALTER TABLE  TestItems
	ALTER COLUMN EnCode NVARCHAR(500)   

	ALTER TABLE  TestItems
	ALTER COLUMN TestName NVARCHAR(500)
	
	ALTER TABLE  TestItems
	ALTER COLUMN ReportEnglishName NVARCHAR(500)
	
	ALTER TABLE  TestItems
	ALTER COLUMN TestChineseNameInReport NVARCHAR(500)

	
	ALTER TABLE  CaseTestItems
	ALTER COLUMN TestItemName NVARCHAR(500)   

	ALTER TABLE  CaseTestItems
	ALTER COLUMN ServiceDetailName NVARCHAR(500)
	
	ALTER TABLE  CaseTestItems
	ALTER COLUMN ServiceItemName NVARCHAR(500)
	
	ALTER TABLE  CaseTestItems
	ALTER COLUMN ServiceTypeName NVARCHAR(500)
END
GO



IF EXISTS(SELECT * FROM sys.columns
WHERE name='EnCode' AND object_id=OBJECT_ID('Base_ServiceItems') AND max_length<1000)
BEGIN
	ALTER TABLE  Base_ServiceItems
	ALTER COLUMN EnCode NVARCHAR(500)   

	ALTER TABLE  Base_ServiceItems
	ALTER COLUMN ItemsName NVARCHAR(500)
	
	ALTER TABLE  Base_ServiceItems
	ALTER COLUMN ReportDisplayName NVARCHAR(500)
	
	
	
END
GO

IF EXISTS(SELECT * FROM sys.columns
WHERE name='Remark' AND object_id=OBJECT_ID('QueueAttendee') AND max_length<1000)
BEGIN
	ALTER TABLE dbo.QueueAttendee
	ALTER COLUMN Remark NVARCHAR(MAX) NULL

	ALTER TABLE dbo.QueueAttendee
	ALTER COLUMN CheckInRemark NVARCHAR(MAX) NULL
END
GO